package com.ant.storage.controller;

import com.ant.storage.common.ResultPage;
import com.ant.storage.pojo.BusinessOut;
import com.ant.storage.service.IBusinessOutService;
import com.ant.storage.common.PageRecv;
import com.ant.storage.common.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/businessOut")
@Api(tags = "业务出库接口")
public class BusinessOutController {

    @Autowired
    IBusinessOutService businessOutService;

    @ApiOperation(value = "业务出库新增")
    @PostMapping("/addBusinessOut")
    public ResultVo addBusinessOut(@RequestBody BusinessOut businessOut){
        return businessOutService.addBusinessOut(businessOut);
    }

    @ApiOperation(value = "业务出库单查询")
    @PostMapping("/queryBusinessOut")
    public ResultPage queryBusinessOut(@RequestBody PageRecv<BusinessOut> pageRecv){
        return businessOutService.queryBusinessOut(pageRecv);
    }

    @ApiOperation(value = "业务出库编辑")
    @PostMapping("/businessOutEnterEdit")
    public ResultVo businessOutEnterEdit(@RequestBody BusinessOut businessOut){
        return businessOutService.businessOutEnterEdit(businessOut,2);
    }

    @ApiOperation(value = "业务出库确认")
    @PostMapping("/businessOutEnterConfirm")
    @Transactional(rollbackFor = Exception.class)
    public ResultVo businessOutEnterConfirm(@RequestBody BusinessOut businessOut){
        businessOutService.businessOutEnterEdit(businessOut,3);
        //对应仓库库存减少
        businessOutService.stockSubtract(businessOut);
        return ResultVo.success("ok");
    }

}
